package com.alon.spring01.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alon.spring01.common.model.Result;
import com.alon.spring01.model.User;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @program: spring01
 * @description: 测试控制器
 * @author: yulongguang
 * @create: 2019-08-12 09:40
 **/
public class TestController {

    public static void main(String[] args) {
        String name = "212";
        String thisName = "1212";
        boolean b = Objects.equals(name, thisName);

        System.out.println(b);
        List<String> lists = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(lists)) {

        }

        //fastjson
        //1.json转object
        //2.json转list
        String jsonStr = "[{\n" +
                "\t\t\"id\": 200,\n" +
                "\t\t\"userName\": \"站分散\",\n" +
                "\t\t\"password\": \"121212\",\n" +
                "\t\t\"age\": 18\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"id\": 201,\n" +
                "\t\t\"userName\": \"咋很难过三\",\n" +
                "\t\t\"password\": \"123\",\n" +
                "\t\t\"age\": 19\n" +
                "\t}\n" +
                "]";
//        User user = JSON.parseObject(jsonStr, User.class);
        List<User> users = JSON.parseArray(jsonStr, User.class);
        System.out.println(users);

        User user = new User();
        user.setUserName("阿龙");
        user.setPassword("123456");
        user.setId(202);
        user.setAge(20);
        String jsonString = JSON.toJSONString(user);
        System.out.println(jsonString);

        List<User> users1 = JSON.parseObject(jsonStr, new TypeReference<List<User>>() {
        });
        System.out.println(users1);
        String jsonStr01 = "{\n" +
                "\t\"code\": 200,\n" +
                "\t\"message\": \"操作成功\",\n" +
                "\t\"data\": {\n" +
                "\t\t\"id\": 100,\n" +
                "\t\t\"userName\": \"张三\",\n" +
                "\t\t\"password\": \"123456\",\n" +
                "\t\t\"age\": 1\n" +
                "\t}\n" +
                "\n" +
                "}";
        Result<User> listResult = JSON.parseObject(jsonStr01, new TypeReference<Result<User>>() {
        });
        System.out.println(JSON.toJSONString(listResult.getData()));

    }

    private static void testString(String name, String realName) {


    }
}
